
%
% This document has designed to be read through as a PDF first.
% Click on the ``Typeset'' button in the toolbar to generate the PDF
% if it is not already visible.
%

%%% PREAMBLE %%%
% You probably want to skip to \begin{document} if this is your first time.

\documentclass[article,oneside]{memoir}
% This command goes at the beginning of every document
% [oneside,article] are two of many options that can be chosen
%   oneside makes each page have the same layout, for printing on only one side 
%     of the paper (change it to twoside to see the difference)
%   article means we're writing a short document only and won't be using special 
%     chapter headings
%   a4paper changes the page dimensions for A4 sized paper 

%%% PACKAGES %%%

\usepackage{graphicx} % Add graphics capabilities
\usepackage{booktabs} % ``Proper'' table layout
\usepackage{amsmath}  % Better maths support
\usepackage[colorlinks=true,linkcolor=red]{hyperref} % Hyperlink capabilities

\usepackage{memhfixc} % This package is required to resolve incompatibilities
                      % with the memoir class & the hyperref package
                      
% \usepackage{pdfsync}
% This package is used to tell TeXShop where things are in the PDF file.
% Command-click at any spot in the PDF and it will jump to the corresponding
% location in the source file.

%%% COMMANDS %%%

% These are two examples of how you can define your own commands.
% These two are used to save on typing.
\newcommand{\pkg}[1]{\textsf{#1}}
\newcommand{\lshort}{\href{http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf}{The Not So Short Introduction to \LaTeX{}}}


% Define the title, author and date of the document.
% If the date is undefined, the current date is substituted.
\title {\LaTeX\ on Mac OS X beginner's guide}
\author{Will Robertson}
%\date{2004-05-06}


%%% BODY OF THE DOCUMENT: %%%
\begin{document}

\maketitle
% Generates a title based on the \title, \author, and \date commands in the preamble.

\chapter{Intro}

This is a simple example \LaTeX{} document written to very briefly introduce a new user to the main features of \LaTeX{} on Mac OS X. It will demonstrate the bare necessities of a basic document. It is designed to be first read as PDF; afterwards the new user should then read through the source code.
% \LaTeX{} is a command that typesets the word ``LaTeX'' in a special way.
% Unless you know what you're doing, the curly brackets are required even though it has no arguments.

The document \lshort{} should be used for technical help. The \href{http://www.esm.psu.edu/mac-tex/}{Mac TeX} website should be used for further reference. The \href{http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes}{\TeX{} FAQ} is invaluable --- if you have a question, it's almost definitely answered there.
% \lshort is a command defined by me in the preamble (see line 27) to print: 
% ``The Not So Short Introduction to LaTeX'' with a hyperlink to the document on the web.
% Sure saves on typing!
% \href{<link>}{<text>} is a command for inserting PDF hyperlinks (provided by hyperref)


\chapter{Terminology}

\TeX{} is a program language for typesetting. \LaTeX{} is built upon \TeX{} and provides very high level access to the structure of your documents. You write plain text \LaTeX{} source files and feed them to the \LaTeX{} program, which outputs a beautifully typeset file\footnote{You may consider the chain analogous to programming (source code to compiler to binary application) or writing HTML (html file to browser to webpage).}. For new users, the most simple program for writing their \LaTeX{} documents (in Mac OS X) and typesetting them is TeXShop. Many people use more complex programs as they become more proficient, such as iTeXMac, Alpha, and Emacs.
% The \footnote command should be fairly self-explanatory.
  
The default on Mac OS X is to use a variant of \LaTeX{} called pdf\LaTeX{}, which means that the typeset output file is PDF. All this means for now is that in TeXShop, ``pdfTeX'' should be ticked in the Typeset menu.
% To quote in LaTeX, use backticks (`) for left quotation marks and straight quote (') for right quotation marks. Double them up (as above) to get ``66's and 99's''


\chapter{TeXShop}

If you are reading this document to learn about TeX on Mac OS X, then hopefully you're reading it in TeXShop. In the toolbar of the source window is a ``Templates'' menu; you should use this when constructing your document from scratch so you don't have to remember all of the commands.

When you typeset your document, \LaTeX{} creates a few other files in the same directory, for various purposes such as error reporting and information about the document. These files will have the same name as your document, but with extensions such as \texttt{.aux} and \texttt{.log}. It is safe to almost always ignore them.


\chapter{Basics}

This is going to be very brief. A \LaTeX{} document is built up of two main components: the \emph{preamble} at the beginning which sets up what features you are going to use in the document; and the \emph{body} where you write the content of your document. What you type into a \LaTeX{} document can be classified into two types: commands and text. A command is prefixed with a backslash and arguments are contained within curly braces; an example is \verb#\emph{emphasised text}# which, when typeset, looks like \emph{emphasised text}. Optional arguments in a command are surrounded with square brackets.
% \verb is a special command that prints out EXACTLY what's inside its delimiters.
% The delimiter itself can be a character that doesn't appear inside the argument (some characters are excluded). For example, \verb/hello/ is the same as \verb.hello. .

\section{Preamble}
% \section{} is next down on the heirachy of document structure. Below this is \subsection and \subsubsection

The preamble is where you set up your file with various options. Most of the stuff in the preamble looks, for example, like \verb#\usepackage{graphicx}#. All this means in this case is that you are telling \LaTeX{} to use the \pkg{graphicx} package, which lets you insert pictures into your document.
% \pkg is a command I defined in the preamble (see line 39 - CMD+L in TeXShop) to style the text I use when referring to packages. If I ever want my packages to look differently (maybe bold instead, for example) all I need to do is change my initial definition.

For now it's okay to ignore the preamble and simply concentrate on getting words onto the page.

\section{Body}

The body is the content of your document. Use structural commands like \verb|\chapter{Basics}| and \verb#\section{Preamble}# to organise your document, and commands like \verb~\emph{meaning}~ to convey the \emph{meaning} of the content. See \lshort{} for information regarding anything and everything that might possibly go in your document: ordered and unordered lists, footnotes, margin notes, quoting environments, code listings, headers,...
% Remember you can use almost any character for \verb delimiters

To customise the way \LaTeX{} actually displays your content (for example, changing the font of the section titles), read the \href{http://www.ctan.org/tex-archive/macros/latex/contrib/memoir/memman.pdf}{memoir class manual}. The first half of the document refers to actual typesetting technicalities and terminology; the actual \LaTeX{} stuff is in the second half.
% The \href command is used to create a hyperlink: the first argument is the file path and the second is the displayed name. In this case, the link points to a pdf file on the internet


\chapter{Maths}

If you use \LaTeX{} to write maths, then you want to use the \pkg{amsmath} package. \LaTeX{} can do maths by itself, but the \pkg{amsmath} package will do it better. Brief examples:

In matrix form $M\ddot X +D\dot X + KX = [0]$, where
% To typeset maths in a paragraph, surround it with dollar signs.

\begin{equation}
  K = \left[\,\begin{matrix}
    k_1+k_2 & -k_2 & 0\\
    -k_2 & k_2+k_3+k_4 & -k_3\\
    0 & -k_3 & k_3+k_4
    \end{matrix}\,\right]
\end{equation}
% Use the equation environment to type single lines of maths

\begin{align}
  m_1{\ddot x_1} & = -k_1x_1+k_2(x_2-x_1),\\
  m_2{\ddot x_2} & = -k_2(x_2-x_1)-k_4x_2+k_3(x_3-x_2),\\
  m_3{\ddot x_3} & = -k_3(x_3-x_2)-k_5x_3.
\end{align}
% Use the align environment as above to align multiple lines of maths

Maths is logical but there is a huge amount you can do with it. Probably Herbert Voss's \href{http://www.ctan.org/tex-archive/info/math/voss/Voss-Mathmode.pdf}{mathmode.pdf} gives the most complete introduction to the topic.


\chapter{Graphics}

Using pdf\LaTeX{} gives us more flexibility with image formats. Any image format may be used, as long as it's one of PDF, JPG or PNG. If you are using regular \LaTeX{} (in this case, ``TeX and Ghostscript'' would be ticked in the Typeset menu in TeXShop) you would \emph{only} be able to use EPS files. A brief description of the file types:

\begin{enumerate}
% This is one of the list environments. Swap ``enumerate'' with ``itemize'' and see the difference...

\item{PDF graphics are used for vector diagrams---see Figure~\ref{fig:pdf} for an example;}
% \ref is a command that is used in conjuction with the \label command to reference objects in your document. It works out what the numbers are supposed to be when the document is compiled.

\item{PNG graphics are lossless raster images used for precise bitmap images---see Figure~\ref{fig:png} for an example.}

\item{JPG graphics are compressed bitmaps usually used for photos---see Figure~\ref{fig:jpg} for an example;}

\end{enumerate}

% REGARDING FIGURES:
% Notice that the figures in the document are not where they are specified in this file. That is because they are wrapped in the figure environment (  \begin{figure}...\end{figure}  ) which means that the figures ``float'' into the best position they can in the document.

\begin{figure}[hbtp]
  % The placing argument [hbtp] can have up to four specifications: this time we're saying we want the figure placed with the following preference: `h'ere first, if not then the `b'ottom of a page, if not again then the `t'op of a page, and if all else fails put it on a `p'age by itself with other floats with nowhere to go.

  \centering % This command centres the figure.
  % If you want to centre regular text, use the center environment (wrap your text with \begin{center}...\end{center} )
  
  \includegraphics[width=0.9\textwidth]{./fig/pdf-example}
  % This is the command that places the image. [width=...] is optional {./fig/pdf-example} is the path to the image. The extension isn't required because LaTeX is clever.
  \caption{An example PDF diagram. It can be infinitely re-scaled without loss of quality while retaining a small file size (try it and see!).}

  \label{fig:pdf}
  % This is the all important \label command. Use it with \ref to refer to objects in your document and have LaTeX keep track of all the details for you.
\end{figure}

See the document \href{http://www.ctan.org/tex-archive/info/epslatex.pdf}{Using imported graphics in \LaTeX{}} for more information. It refers only to EPS files, but the information it has is still accurate. It was written before pdf\TeX{} but the techniques it covers are still 100\% relevant.

\begin{figure}[tp]
  \centering
  \includegraphics[height=10em]{./fig/png-example}
  \caption{An example PNG image. Useful for bitmap pictures with exact output required.}
  \label{fig:png}
\end{figure}

\begin{figure}[bp]
  % In this case we want this figure at the `t'op of a page, or on a `p'age by itself
  \centering
  \includegraphics[scale=1.5]{./fig/jpg-example}
  \caption{An example JPG picture. This format is good for photos because the compression is efficient but lossy.}
  \label{fig:jpg}
\end{figure}
  
% It is sometimes tricky to get figures where you would like. The only way to get a feel for it all is to practice! Read the document below.


\chapter{Tables}

To typeset tables you really want the \pkg{booktabs} package. This package has been designed with the goal of book-quality output---the manual contains an excellent introduction on the technicalities of table layout. First and foremost is the mantra ``never use vertical lines in tables''. See Table~\ref{tab:booktabs} for an example, and \href{http://www.tug.org/tex-archive/macros/latex/contrib/booktabs/booktabs.pdf}{the \pkg{booktabs} manual} for full details.


\begin{table}[htbp]
  \centering
  \begin{tabular}{ @{} lcr @{} }
    % lcr means to align the first column to the left, the second column to the centered, and the right column to the right.
    % The @{} are a shorthand way of telling booktabs to cut off the extra space around the table.
    \toprule
    \multicolumn{2}{c}{Item}             \\ % \\ means ``newline'', used to separate columns
    \cmidrule{1-2} % Draw a line from the first column to the second column
    Animal    & Description & Price (\$) \\
    % Ampersands (&) are used to separate rows.
    % Because the dollar sign is used for maths mode, if you want to use it in your text it must be _escaped_ by preceeding it with a backslash.
    \midrule
    Gnat            & per gram    & 13.65      \\
                    & each        &  0.01      \\
    Gnu             & stuffed     & 92.50      \\
    Emu             & stuffed     & 33.33      \\
    Armadillo       & frozen      &  8.99      \\
    \bottomrule
  \end{tabular}
  \caption{An example table, adapted from the \pkg{booktabs} package}
  \label{tab:booktabs}
\end{table}


\chapter{Fonts}

There are many different text fonts that you may choose to use in \LaTeX{}. See the
\href{http://www.tug.org/tex-archive/macros/latex/required/psnfss/psnfss2e.pdf}{postscript font guide} for some of the details. Note that it is technically possible to convert \emph{any} font for use in \LaTeX{}---it can however be a laborious process. See Bruno Voisin's tutorial \href{http://homepage.mac.com/bkerstetter/tex/fonttutorial-current.html}{Installing Fonts for \LaTeX\ on OS~X} (Definitely an advanced topic, only included here for completeness.)

% I should probably mention: the tilde character ~ is used as a space that is not ever broken across lines.


\end{document}